import Vue from "vue";
import Vuex from "vuex";
import app from "./modules/app";
import dict from "./modules/dict";
import user from "./modules/user";
import tagsView from "./modules/tagsView";
import permission from "./modules/permission";
import settings from "./modules/settings";
import getters from "./getters";

Vue.use(Vuex);

const store = new Vuex.Store({
  modules: {
    app,
    dict,
    user,
    tagsView,
    permission,
    settings,
  },
  getters,
  state: {
    //入库添加明细
    electricInDetailsList: null,
    transformerInDetailsList: null,
    terminalInDetailsList: null,
    moduleInDetailsList: null,
    concentratorInDetailsList: null,
    otherInDetailsList: null,
    taskNo: "",
    //出库添加明细
    electricOutDetailsList: null,
    transformerOutDetailsList: null,
    terminalInDetailsList: null,
    moduleOutDetailsList: null,
    concentratorOutDetailsList: null,
    otherOutDetailsList: null,
    outTaskNo: "",
  },
  mutations: {
    addDetailsDelete(state, payload) {
      const { indexArray } = payload;
      const { electricInDetailsList } = state;
      let newData = electricInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.electricInDetailsList = newData;
    },
    addDetailsDeleteOne(state, payload) {
      const { indexArray } = payload;
      const { transformerInDetailsList } = state;
      let newData = transformerInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.transformerInDetailsList = newData;
    },
    addDetailsDeleteTwo(state, payload) {
      const { indexArray } = payload;
      const { terminalInDetailsList } = state;
      let newData = terminalInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.terminalInDetailsList = newData;
    },
    addDetailsDeleteThree(state, payload) {
      const { indexArray } = payload;
      const { moduleInDetailsList } = state;
      let newData = moduleInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.moduleInDetailsList = newData;
    },
    addDetailsDeleteFour(state, payload) {
      const { indexArray } = payload;
      const { concentratorInDetailsList } = state;
      let newData = concentratorInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.concentratorInDetailsList = newData;
    },
    addDetailsDeleteFive(state, payload) {
      const { indexArray } = payload;
      const { otherInDetailsList } = state;
      let newData = otherInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.otherInDetailsList = newData;
    },
    //出库
    addOutDetailsDelete(state, payload) {
      const { indexArray } = payload;
      const { electricOutDetailsList } = state;
      let newData = electricOutDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.electricOutDetailsList = newData;
    },
    addOutDetailsDeleteOne(state, payload) {
      const { indexArray } = payload;
      const { transformerOutDetailsList } = state;
      let newData = transformerOutDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.transformerOutDetailsList = newData;
    },
    addOutDetailsDeleteTwo(state, payload) {
      const { indexArray } = payload;
      const { terminalInDetailsList } = state;
      let newData = terminalInDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.terminalInDetailsList = newData;
    },
    addOutDetailsDeleteThree(state, payload) {
      const { indexArray } = payload;
      const { moduleOutDetailsList } = state;
      let newData = moduleOutDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.moduleOutDetailsList = newData;
    },
    addOutDetailsDeleteFour(state, payload) {
      const { indexArray } = payload;
      const { concentratorOutDetailsList } = state;
      let newData = concentratorOutDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.concentratorOutDetailsList = newData;
    },
    addOutDetailsDeleteFive(state, payload) {
      const { indexArray } = payload;
      const { otherOutDetailsList } = state;
      let newData = otherOutDetailsList.filter(
        (item) => !indexArray.some((i) => item.assetsId == i.assetsId)
      );
      state.otherOutDetailsList = newData;
    },
  },
});

export default store;
